<?php

namespace app\command;

use app\admin\model\base\SysConfig;
use app\admin\model\iot\ScanBagStatistics;
use redis\RedisTools;
use think\console\Command;
use think\console\Input;
use think\console\Output;

class BagStatistics extends Command
{
    protected function configure()
    {
        $this->setName('BagStatistics')->setDescription('二维码识别数据每日统计');
    }

    protected function execute(Input $input, Output $output)
    {
        //加载系统配置
        SysConfig::loadConfig();
        //统计数据每日的数据
        $arr = [
            'V1_Way_7_0',
            'V1_Way_7_1',
            'V1_Way_7_2',
            'V1_Way_7_3',
            'V1_Way_7_4',
            'V1_Way_7_5',
            'V1_Way_7_6',
            'V1_Way_7_7',
            'V1_Way_7_8'
        ];
        $redis = RedisTools::getInstance(config('cache.stores.redis'), 0)->getRedis();
        $date = date('Y-m-d',time());
        foreach ($arr as $item){
            $key = $item.'_'.$date.'_num';
            $num = $redis->get($key);
            $num = !empty($num) ? $num : 0;
            ScanBagStatistics::create(['date'=>$date,'key'=>$item,'num'=>$num,'create_time'=>time(),'update_time'=>time()]);
        }
        die;
    }
}